package com.zmn.plat.admin.controller.part.price;

import java.util.Date;
import java.util.Objects;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.zmn.common.utils.date.DateUtil;
import com.zmn.plat.admin.controller.part.PartBaseController;
import com.zmn.plat.model.entity.part.PartSkuPrice;
import com.zmn.plat.model.vo.part.PartSkuVO;

/**
 * 类描述： PartSkuPriceListController 配件价格
 *
 * @author DaiZhichao
 * @since 2018/10/23 16:54
 */

@Controller
@RequestMapping("/part/price")
public class PartSkuPriceListController extends PartBaseController {

    private Logger logger = LoggerFactory.getLogger(PartSkuPriceListController.class);

    /**
     * 描述:配件价格详情页面
     *
     * @author DaiZhichao
     * @since 2018/11/6 20:39
     */
    // region 配件价格详情
    @RequestMapping("/detail")
    public String detail(@RequestParam(required = true) int skuId, Model model, HttpServletRequest request) {

        if (skuId == 0) {
            return "redirect:/error";
        }

        PartSkuPrice skuPrice = partSkuPriceService.findByKey(skuId);
        if (Objects.isNull(skuPrice)) {
            String mcStaffName = getMcStaffName(request);
            Date now = DateUtil.getNow();
            skuPrice = new PartSkuPrice(skuId, (long)0, (long)0, (long)0, mcStaffName, now);
        }
        PartSkuVO part = partSkuService.findVOByKey(skuId);
        model.addAttribute("part", part);
        model.addAttribute("partPrice", skuPrice);
        return "part/price/detail";
    }
    // endregion

}
